/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "SkyEffectManager.h"

namespace Fish3D
{
	enum SkyBoxes
	{
		Sky_Box_ClubTropicana,
		Sky_Box_EarlyMorning,
		Sky_Box_Clouds,

		Sky_Box_Num,
	};

	Ogre::String __skyBoxes[Sky_Box_Num] = 
			   {"Sky/ClubTropicana",
				"Sky/EarlyMorning",
				"Sky/Clouds"};

	Ogre::Vector3 __sunPosition[Sky_Box_Num] = 
			   {Ogre::Vector3(0,10000,0),
				Ogre::Vector3(0,10000,90000),
				Ogre::Vector3(0,10000,0)};

	Ogre::Vector3 __sunColor[Sky_Box_Num] = 
			   {Ogre::Vector3(1, 0.9, 0.6),
				Ogre::Vector3(1,0.6,0.4),
				Ogre::Vector3(0.45,0.45,0.45)};

	int __currentSkyBox = 0;

	SkyEffectManager::SkyEffectManager(Ogre::SceneManager* sceneMgr)
		: _sceneMgr(sceneMgr)
	{
		// Set default ambient light
		_sun = _sceneMgr->createLight("SunLight");
		updateSky();
	}

	void SkyEffectManager::updateSky()
	{
		// Create the SkyBox
		_sceneMgr->setAmbientLight(Ogre::ColourValue(__sunColor[__currentSkyBox].x,__sunColor[__currentSkyBox].y,__sunColor[__currentSkyBox].z));

		_sceneMgr->setSkyBox(true, __skyBoxes[__currentSkyBox], 99999*3, true);
		
		// Create Sun light
		_sun->setPosition(__sunPosition[__currentSkyBox]);
		_sun->setDiffuseColour(1, 1, 1);
		_sun->setSpecularColour(__sunColor[__currentSkyBox].x,__sunColor[__currentSkyBox].y,__sunColor[__currentSkyBox].z);
	}


	void SkyEffectManager::update(float deltaT)
	{
	}

	void SkyEffectManager::injectKeyDown(const OIS::KeyEvent& evt)
	{
		switch(evt.key){
			case OIS::KC_1:
				__currentSkyBox=0;
				break;
			case OIS::KC_2:
				__currentSkyBox=1;
				break;
			case OIS::KC_3:
				__currentSkyBox=2;
				break;
		}
		updateSky();
	}

}


